package com.catgod007.yudada.mapper;

import com.catgod007.yudada.model.dto.statistic.AppAnswerCountDTO;
import com.catgod007.yudada.model.dto.statistic.AppAnswerResultCountDTO;
import com.catgod007.yudada.model.entity.UserAnswer;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author Cat God 007
* @description 针对表【user_answer(用户答题记录)】的数据库操作Mapper
* @createDate 2024-10-01 11:12:32
* @Entity com.catgod007.yudada.model.entity.UserAnswer
*/
public interface UserAnswerMapper extends BaseMapper<UserAnswer> {
    /**
     * 热门应用排行统计
     * @return
     */
    @Select("select appId,count(distinct userId) as answerCount from " +
            "user_answer group by appId order by answerCount desc limit 10;")
    List<AppAnswerCountDTO> doAppAnswerCount();

    /**
     * 应用回答分布统计
     * @param appId
     * @return
     */
    @Select("select resultName, count(resultName) as resultCount from user_answer\n" +
            "where appId = #{appId}\n" +
            "group by resultName order by resultCount desc;")
    List<AppAnswerResultCountDTO> doAppAnswerResultCount(Long appId);



}




